package com.bckj.fastboot.security.service;

import com.bckj.fastboot.security.constant.SecurityConstants;
import com.bckj.fastboot.security.model.AuthUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

@Slf4j
@RequiredArgsConstructor
public class FastUserDetailsServiceImpl implements FastUserDetailsService {

    private final FastUserDetailsProvider oauthDetailsProvider;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return getUserDetails(oauthDetailsProvider.getUserDetails(username));
    }

    @Override
    public UserDetails loadByUser(AuthUser user) {
        return loadUserByUsername(user.getPhone());
    }

    /**
     * 是否支持此客户端校验
     * @param clientId 目标客户端
     * @return true/false
     */
    @Override
    public boolean support(String clientId, String grantType) {
        return SecurityConstants.GRANT_TYPE_SMS.equals(grantType);
    }
}
